<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class SelectController extends Controller
{
   
    public function getIndex()
    {
        //初始化
        //获取全部以及分类
       $type = DB::table('type')->where('pid',0)->get();
      // dd($type);

      //获取配置信息
       $config = DB::table('config')->first();

      //友情链接
       $blinks = DB::table('blink')->get();

      //遍历下部的栏目
      $datas = self::pushCates(self::pushType(),0);

      // var_dump($type);
       return view('Home.loveser.select',['type'=>$type,'config'=>$config,'blinks'=>$blinks,'datas'=>$datas]);
      
    }

     //获取全部一级分类板块
    public static function pushType()
    {
        return $cates = DB::table('type')->get();


    }

    
    //获取二级分类
    public  static function pushCates($cates,$pid)
    {
        $data = [];
        foreach($cates as $k=>$v)
        {
            if($v->pid == $pid){

               $v->sub = self::pushCates($cates,$v->id);
               $data[] = $v;
            }
        }
        return $data;
    }

    //捐款查询
    public function postFind(Request $request)
    {
        //查询
        $res = DB::table('loveuser')->where('username','like','%'.$request->username.'%')->get();
        
        //获取全部以及分类
        $type = DB::table('type')->where('pid',0)->get();
        // dd($type);

        //获取配置信息
        $config = DB::table('config')->first();

        //友情链接
        $blinks = DB::table('blink')->get();

        //遍历下部的栏目
        $datas = self::pushCates(self::pushType(),0);

        // var_dump($type);
       return view('Home.loveser.linefind',['type'=>$type,'config'=>$config,'blinks'=>$blinks,'datas'=>$datas,'res'=>$res]);
    }

   //网上捐款查询
    public function postSel(Request $request)
    {
         //查询
        $res = DB::table('loveusersl')->where('username','like','%'.$request->username.'%')->get();
        
        //获取全部以及分类
        $type = DB::table('type')->where('pid',0)->get();
        // dd($type);

        //获取配置信息
        $config = DB::table('config')->first();

        //友情链接
        $blinks = DB::table('blink')->get();

        //遍历下部的栏目
        $datas = self::pushCates(self::pushType(),0);

        // var_dump($type);
       return view('Home.loveser.find',['type'=>$type,'config'=>$config,'blinks'=>$blinks,'datas'=>$datas,'res'=>$res]);
    }

}
